import 'dart:io';
import 'package:basic_common/common_exports.dart';
import 'package:basic_common/local_storage.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/services.dart';
import 'global_info.dart';

/* 
 * @description: //全局初始化配置
 * @author: Jane 
 * @date: 2023-09-11 17:55:58
 */
class GlobalConfig {
  /// 初始化
  static Future init() async {
    //与原生通信
    WidgetsFlutterBinding.ensureInitialized();
    // 强制竖屏
    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    setSystemUi();
    await LocalStorage.init();
    await GlobalInfo.initPlatformState();
    // 初始化 EasyLoading
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)
      ..indicatorType = EasyLoadingIndicatorType.fadingCircle
      ..loadingStyle = EasyLoadingStyle.dark
      ..indicatorSize = 45.0
      ..radius = 10.0
      ..progressColor = Colors.yellow
      ..backgroundColor = Colors.green
      ..indicatorColor = Colors.yellow
      ..textColor = Colors.yellow
      ..maskColor = Colors.transparent
      ..userInteractions = true
      ..dismissOnTap = false;
  }

  // 设置状态栏
  static void setSystemUi() {
    if (Platform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }

}
